package ru.amse.tsyganov.jumleditor.model;

import java.util.HashSet;
import java.util.Set;


/**
 * A partition is a mechanism for dividing the 
 * states of an activity graph into groups. 
 * Partitions often correspond to organizational
 * units in a business model. They may be used to 
 * allocate characteristics or resources among 
 * the states of an activity graph. It should be 
 * noted that Partitions do not impact the dynamic 
 * semantics of the model but they help to allocate 
 * properties and actions for various purposes.
 * 
 * @author Dmitry Tsyganov
 *
 */
public class Partition extends ModelElement {
	
	/**
	 * Specifies the states that belong to the partition. 
	 * They need not constitute a nested region.
	 */
	private final Set<State> contents;
	
	private ActivityGraph activityGraph;
	
	public Partition() {
		contents = new HashSet<State>();
	}
	
	public void addState(State state) {
		if (state == null) {
			throw new IllegalArgumentException();
		}
		contents.add(state);
		state.setPartition(this);
	}
	
	public boolean removeState(State state) {
		if (state == null) {
			throw new IllegalArgumentException();
		}
		return contents.remove(state);
	}

	public Iterable<State> getContents() {
		return contents;
	}

	public ActivityGraph getActivityGraph() {
		return activityGraph;
	}

	public void setActivityGraph(ActivityGraph activityGraph) {
		if (activityGraph == null) {
			throw new IllegalArgumentException();
		}
		this.activityGraph = activityGraph;
	}
}
